package com.learn.temp.service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CalendarDemo {

    public static void main(String[] args) {
        System.out.println("完整显示日期时间:");
        DateFormat fdate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = fdate.format(new Date());
        System.out.println(str);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        System.out.println("年:" + calendar.get(Calendar.YEAR));
        System.out.println("月:" + calendar.get(Calendar.MONTH));
        System.out.println("分钟:" + calendar.get(Calendar.MINUTE));
        System.out.println("当前年的第n天:" + calendar.get(Calendar.DAY_OF_YEAR));
        System.out.println("当前月第n天:" + calendar.get(Calendar.DAY_OF_MONTH));
        calendar.add(Calendar.HOUR_OF_DAY, 3);
        System.out.println("3小时后的时间:" + calendar.getTime());
        str = fdate.format(calendar.getTime());
        System.out.println(str);
        Calendar cn = Calendar.getInstance();
        cn.add(cn.HOUR_OF_DAY, -13);
        System.out.println("时间比较:" + cn.compareTo(calendar));
        System.out.println("时间比较:" + calendar.compareTo(cn));
        System.out.println("时间点:" + fdate.format(cn.getTime()));
    }
}
